<template>
  <div class="sys-template-view">
    <div class="tips" v-if="module.includes(['universal', 'paas'])">可在右侧勾选字段，预览效果</div>
      <!-- {{module}} -->
    <!-- PAAS和触发器系统消息支持修改标题和内容 -->
    <div class="view" v-if="module !== 'paas' && module !== 'project' && !isTrigger">

      <h5>{{sysTitle}}</h5>
      <h6>{{sysContent}}</h6>
              
      <template v-for="item in sysDisplayFieldCheckMap">
        <div 
          v-show="sysCheckKeyMap.includes(item.key)"
          class="item-content"
          :key="item.key">
          <span>{{item.value}}：</span>
          <!-- <b>{{item.defaultValue}}</b> -->
          <el-tooltip :content="item.defaultValue" placement="left-start">
            <b>{{item.defaultValue}}</b>
          </el-tooltip>
        </div>
      </template>

      <div class="item-footer">{{ new Date() | fmt_datetime}}</div>
    </div>

    <el-form label-position="top" class="paas-template-form" v-else>
      <el-form-item>
        <el-input v-model="title" maxlength="100" placeholder="请输入标题" :rule="[{ required: true, message: '请输入标题', trigger: 'blur' }]"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="subTiltle" maxlength="100" placeholder="比如：您有一个文件被修改，请查看" :rule="[{ required: true, message: '请输入', trigger: 'blur' }]"></el-input>
      </el-form-item>
      <el-form-item class="content">
        <!-- <el-input v-model="formValue.content" type="textarea" rows="10" disabled></el-input> -->
        <div class="item-content" >
          <template v-for="(item, index) in sysDisplayFieldCheckMap" >
            <div class="item-content__txt" :key="index" v-show="sysCheckKeyMap.includes(item.key)">
              <span>{{item.value}}：</span>
              <!-- <b>{{item.defaultValue}}</b> -->
              <el-tooltip :content="item.defaultValue" placement="left-start">
                <b>{{item.defaultValue}}</b>
              </el-tooltip>
            </div>
          </template>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  // 系统模版预览模块
  name:'sys-template-view',

  props:{
    module: {
      type: String,
      default: ''
    },
    sysTitle:{
      type:String,
      default:''
    },

    sysContent:{
      type:String,
      default:''
    },

    // 所有的展示字段列表
    sysDisplayFieldCheckMap:{
      type:Array,
      required:true
    },

    // 需要展示的字段
    sysCheckKeyMap:{
      type:Array,
      required:true
    },

    // 是否是触发器
    isTrigger: {
      type: Boolean,
      default: false
    },
  },
  computed: {
    title: {
      get() {
        return this.sysTitle
      },
      set(val) {
        this.$emit('update:sysTitle', val);
      }
    },
    subTiltle: {
      get() {
        return this.sysContent
      },
      set(val) {
        this.$emit('update:sysContent', val);
      }
    }
  },

  watch: {
    // sysCheckKeyMap: {
    //   handler(n ,o) {
    //     this.formValue.content = n
    //   },
    //   deep: true,
    //   immediate: true
    // }
  },
  data() {
   return {
    formValue: {
      title: '表单修改通知', 
      subTitle: '您有一个表单被修改，请查看', 
      content: '客户名称：江南机械设备有限公司'
    }
   }
  }
}
</script>


<style lang="scss" scoped>
.sys-template-view{
  width:327px;
  .tips{
    font-size: 14px;
    font-weight: 400;
    color: #595959;
    line-height: 22px;
  }
  .view{
    width: 100%;
    background: #FFFFFF;
    border-radius: 7px;
    padding-top:12px;
    margin-top:12px;
    border: 1px solid #d9d9d9;
    h5,h6{
      margin:0;
      padding:0 13px;
    }
    h5{
      font-size: 15px;
      font-weight: 400;
      color: #262626;
      line-height: 21px;
    }
    h6{
      font-size: 12px;
      font-weight: 400;
      color: #262626;
      line-height: 17px;
      margin-top:11px;
    }
    .item-content{
      font-size: 12px;
      font-weight: 400;
      color: #8C8C8C;
      line-height: 17px;
      margin-top:11px;
      padding:0 13px;
      b{
        color:#262626;
        font-weight: 400;
      }
    }
    .item-footer{
      margin-top:32px;
      font-size: 12px;
      font-weight: 400;
      color: #8C8C8C;
      line-height: 29px;
      padding:0 13px;
      border-top:1px solid #E8E8E8;
    }
  }
  .paas-template-form {
    .item-content{
        font-size: 14px;
        min-height: 210px;
        font-weight: 400;
        color: #8C8C8C;
        line-height: 17px;
        padding: 13px 10px;
        border-radius: 4px;
        /* margin-top:12px; */
        border: 1px solid #d9d9d9;
        box-sizing: border-box;
        
        b{
          color:#262626;
          font-weight: 400;
        }
        .item-content__txt{
          width: 240px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          &:not(:first-child) {
            margin-top: 8px;
          }
        }
      }
      .item-footer{
        margin-top:32px;
        font-size: 12px;
        font-weight: 400;
        color: #8C8C8C;
        line-height: 29px;
        padding:0 13px;
        border-top:1px solid #E8E8E8;
      }
      .el-input--small{
        font-size: 14px;
      }
  }

  ::v-deep .el-form-item--small.el-form-item{
    margin-bottom: 12px;
    &:last-child {
      margin-bottom: 0;
    }
  }
}
</style>
